from django.db import models


# Create your models here.

class GoodsClass(models.Model):
    g_class = models.CharField(max_length=20, verbose_name='分类')

    def __str__(self):
        return str(self.g_class)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '货物分类'
        verbose_name_plural = verbose_name


class Goods(models.Model):
    name = models.CharField(max_length=20, verbose_name='名称')
    belong_class = models.ForeignKey(to=GoodsClass, verbose_name='所属类别', on_delete=models.CASCADE)
    detail = models.TextField(verbose_name='描述', blank=True, null=True)
    price = models.CharField(max_length=20, verbose_name='价格')
    image = models.FileField(upload_to='img/shop_web', verbose_name='图片')

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '货物'
        verbose_name_plural = verbose_name
